<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta name="baidu-site-verification" content="UqlC4pwKIm">
  <meta name="baidu-site-verification" content="d3U0dGeqGw">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">



  <meta name="google-site-verification" content="9Ho8iwjF7bDNkvQpVQHlhFPHnsfuMWlsOvTTgEPIuy4">














  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Roboto Slab:300,300italic,400,400italic,700,700italic|Roboto Slab:300,300italic,400,400italic,700,700italic|Lobster Two:300,300italic,400,400italic,700,700italic|PT Mono:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  







<link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="https://cdn.jsdelivr.net/gh/lopyfrontend/common@0.0.1/icon/favicon-180x180.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="https://cdn.jsdelivr.net/gh/lopyfrontend/common@0.0.1/icon/favicon-32x32.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="https://cdn.jsdelivr.net/gh/lopyfrontend/common@0.0.1/icon/favicon-16x16.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="php,js,rsa,">





  <link rel="alternate" href="/atom.xml" title="码奴假娃" type="application/atom+xml">






<meta name="description" content="rsa的js加密和php解密群里的同志需要的前端js加密，后端php解密的实例">
<meta name="keywords" content="php,js,rsa">
<meta property="og:type" content="article">
<meta property="og:title" content="rsatitle">
<meta property="og:url" content="https://blog.lopygo.com/2017/2017-2017-03-02-js-php-rsa/index.html">
<meta property="og:site_name" content="码奴假娃">
<meta property="og:description" content="rsa的js加密和php解密群里的同志需要的前端js加密，后端php解密的实例">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2025-09-16T17:33:20.676Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="rsatitle">
<meta name="twitter:description" content="rsa的js加密和php解密群里的同志需要的前端js加密，后端php解密的实例">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: 'undefined',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://blog.lopygo.com/2017/2017-2017-03-02-js-php-rsa/">





  <title>rsatitle | 码奴假娃</title>
  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-136884610-2', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?52567a573db99b54cccb66af4c41822b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">码奴假娃</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">裸皮狗</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br>
            
            公益404
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://blog.lopygo.com/2017/2017-2017-03-02-js-php-rsa/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Tony Java Z">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="码奴假娃">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">rsatitle</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-01T16:00:01+00:00">
                2017-03-02
              </time>
            

            
              <span class="post-meta-divider">|</span>
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              
                <span class="post-meta-item-text">更新于&#58;</span>
              
              <time title="更新于" itemprop="dateModified" datetime="2025-09-16T17:33:20+00:00">
                2025-09-17
              </time>
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/develop/" itemprop="url" rel="index">
                    <span itemprop="name">develop</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2017/2017-2017-03-02-js-php-rsa/" class="leancloud_visitors" data-flag-title="rsatitle">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2,750
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  15
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <script src="/assets/js/APlayer.min.js"> </script><p>rsa的js加密和php解密<br>群里的同志需要的前端js加密，后端php解密的实例<br><a id="more"></a>  </p>
<h1 id="开始说明"><a href="#开始说明" class="headerlink" title="开始说明"></a>开始说明</h1><p>后面有一个实例</p>
<h1 id="javascript加密"><a href="#javascript加密" class="headerlink" title="javascript加密"></a>javascript加密</h1><h2 id="引入相关的js库"><a href="#引入相关的js库" class="headerlink" title="引入相关的js库"></a>引入相关的js库</h2><blockquote>
<p>jsbn.js ,</p>
<p>prng4.js ,</p>
<p>rng4.js ,</p>
<p>rsa.js ,</p>
<p>base64.js</p>
</blockquote>
<p>他们的远程目录为： <a href="http://www-cs-students.stanford.edu/~tjw/jsbn/" target="_blank" rel="noopener">http://www-cs-students.stanford.edu/~tjw/jsbn/</a></p>
<p>前端代码：<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://www-cs-students.stanford.edu/~tjw/jsbn/jsbn.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://www-cs-students.stanford.edu/~tjw/jsbn/prng4.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://www-cs-students.stanford.edu/~tjw/jsbn/rng.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://www-cs-students.stanford.edu/~tjw/jsbn/rsa.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://www-cs-students.stanford.edu/~tjw/jsbn/base64.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>本 blog 也拷贝了这几个库，网址的目录为： <a href="http://blog.lopy.win/assets/rsa" target="_blank" rel="noopener">http://blog.lopy.win/assets/rsa/</a> ，将几个文件名加在后面就可以了。</p>
<p>github地址：<a href>https://github.com/uljjmhn520/uljjmhn520.github.io/tree/master/assets/rsa</a></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- jquery 方便dom操作 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"//cdn.bootcss.com/jquery/2.1.3/jquery.min.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!-- 本blog的js文件 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://blog.lopy.win/assets/rsa/jsbn.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://blog.lopy.win/assets/rsa/prng4.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://blog.lopy.win/assets/rsa/rng.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://blog.lopy.win/assets/rsa/rsa.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://blog.lopy.win/assets/rsa/base64.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>test —————–</p>

<p>test —————– end</p>
<h2 id="js代码第一部分"><a href="#js代码第一部分" class="headerlink" title="js代码第一部分"></a>js代码第一部分</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//创建一个rsa类，只有一个加密方法，构造函数为公钥中的 n 和 e 也就是模和指数。</span></span><br><span class="line"><span class="keyword">var</span> MyRsa = <span class="function"><span class="keyword">function</span>(<span class="params">module,eVal</span>)</span>&#123;</span><br><span class="line">    <span class="built_in">module</span> = <span class="built_in">module</span> || <span class="string">''</span>;</span><br><span class="line">    eVal = eVal || <span class="string">'010001'</span>;</span><br><span class="line">    <span class="keyword">var</span> rsaObj = <span class="keyword">new</span> RSAKey();</span><br><span class="line"></span><br><span class="line">    <span class="comment">//构造函数</span></span><br><span class="line">    <span class="keyword">var</span> init = <span class="function"><span class="keyword">function</span>(<span class="params">module,eVal</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(<span class="built_in">module</span>)&#123;</span><br><span class="line">            rsaObj.setPublic(<span class="built_in">module</span>,eVal);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">    init(key,eVal);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//加密</span></span><br><span class="line">    <span class="keyword">this</span>.encrypt = <span class="function"><span class="keyword">function</span>(<span class="params">str</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">var</span> strEncoded = rsaObj.encrypt(str);</span><br><span class="line">        <span class="keyword">if</span>(!strEncoded)&#123;</span><br><span class="line">            alert(<span class="string">'hello what\'s your name'</span>);</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> hex2b64(strEncoded);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="js代码第二部分"><a href="#js代码第二部分" class="headerlink" title="js代码第二部分"></a>js代码第二部分</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//n和e为rsa的模和指数，他们的值是从密钥对中获得的，后文会给出php 中获取的方法</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> n =<span class="string">"E0F1E67A3E1E54B1820A481F1DFC98545542B85EAEC149627591593C19A25B3B6CDAAA9346D83EF695193FA268E3ED27C9B57DCFB5B6FB873D646FA3947105E4ACF07EDF623D321881D8930E0CFD391191F2EB3B3EB3DF2409F25B96B2BD4C5D2EAF42B43059D2FDDBAF5BE51E7F66E69B617FE319DFC2AD2567A841D765EB0DF5BAB631146EB6FD5688028658A0AEAF1CBD470BF437BCFA6641159E8C2F857B0C7D806326C6D3037DEAD1EC463673E0CA30D51EAF7F70EB7AFD46A765FB5FB4C89791A4CF4C4072E4D29D5DEDE90D75DC2D9669AEB888133F349179264EFF2DF0BCEFDA11FDAC32B57F75E2D2072ADC117DDAC3BEA8F431253228594BF0419B"</span>;</span><br><span class="line"><span class="keyword">var</span> e = <span class="string">'010001'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> myRsa = <span class="keyword">new</span> MyRsa(n,e);</span><br><span class="line"><span class="keyword">var</span> encoded = myRsa.encrypt(<span class="string">'hello world'</span>);</span><br><span class="line"><span class="built_in">console</span>.log(encoded);</span><br><span class="line"></span><br><span class="line"><span class="comment">// result，以下为结果之一，每次加密的结果都可能不一样</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// XJJeZhc4tYp50OXDAyBS6aK0lWOPNR6IVOM4auccxb+uk0+d5GewFq9ffAWhlBpAiRTuo1IbKm8e23UdU3kbIFs9nNAMCSdj/2FL3C9NrXlW67Jfs6azAMHMHKW3f3rXPCRMTvFGq09KdobwLiy71GidRZtbQYQEaZ8QhHpZC/QYem9EAdu4ULdBX5e1uigIPm3ukzK6RUKRbBYM44ApoL6kNUdbELvC2J6psqs1YxprwAw9D5C8N41tWFRwx7MIPx83TG8aGYDCU/q1E5Xd7fDpXlm4gZxPPXMHwIT4WJBvzDZoCCpxJSEYEzHzfF6HTTWcWo8BBbUeC8qssCHiyA==</span></span><br></pre></td></tr></table></figure>
<h1 id="php解密"><a href="#php解密" class="headerlink" title="php解密"></a>php解密</h1><h2 id="私钥"><a href="#私钥" class="headerlink" title="私钥"></a>私钥</h2><p>解密用的私钥，与加密用的公钥为一对。</p>
<p>密钥对用php函数 <strong>openssl_pkey_new</strong> 和 <strong>openssl_pkey_export</strong> 生成；公钥可用已存在的私钥生成，后文中会介绍</p>
<p>以下为某一个私钥</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">-----BEGIN PRIVATE KEY-----</span><br><span class="line">MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDg8eZ6Ph5UsYIK</span><br><span class="line">SB8d/JhUVUK4Xq7BSWJ1kVk8GaJbO2zaqpNG2D72lRk/omjj7SfJtX3Ptbb7hz1k</span><br><span class="line">b6OUcQXkrPB+32I9MhiB2JMODP05EZHy6zs+s98kCfJblrK9TF0ur0K0MFnS/duv</span><br><span class="line">W+Uef2bmm2F/4xnfwq0lZ6hB12XrDfW6tjEUbrb9VogChligrq8cvUcL9De8+mZB</span><br><span class="line">FZ6ML4V7DH2AYybG0wN96tHsRjZz4Mow1R6vf3Drev1Gp2X7X7TIl5Gkz0xAcuTS</span><br><span class="line">nV3t6Q113C2Waa64iBM/NJF5Jk7/LfC879oR/awytX914tIHKtwRfdrDvqj0MSUy</span><br><span class="line">KFlL8EGbAgMBAAECggEBAIWKtpRd6m3HT/dAp9CKk/iFAW4pL8AqC9zWJE7MvRlC</span><br><span class="line">ZzZNy89kM8T58RpZFcIymctjBsTYEUC0IhtNN6S5kJEYplH71fuUkP4NEAhoZ7CI</span><br><span class="line">oMfBJNPtvwxLJ2l+RrCg9DTx8Ty986WR9ejeOmBnrDQ9jJ16unKfxWEOb9JeyO/I</span><br><span class="line">pcuNi1+FKjCJDExNrEbPsiVdHK3tWI7a3lKVA6pTVSypjp3gLlbxwHpgVaEm+dak</span><br><span class="line">RFiPoyCoxYigQhsmnKp0ou+2qrJIl7b6NM+mfWD/o21zhAD3q/2vDfc5M661Uhlj</span><br><span class="line">Q/CvinB6P39Zs4gIhZa17AeZOXEgekcx/I068vLRKLkCgYEA9xaztzsvJTOQOjYX</span><br><span class="line">ZAaTssVO1VpDp9YbaXzLhrmc9HZVTgIiuDumKHrZ98r0yxQ21CszyJUEVbDSmVze</span><br><span class="line">hYnkMpC6lV03H8KuODNtjbeUkEw87g3+wiEuDAPUPHpVo/Afzxnd3kvH0dOKkMkY</span><br><span class="line">H09tuBbI7JXEbeJtxOuCxc7QCT0CgYEA6Q7AXNnerxcIcfBmFQR2HArmcIQcfmyx</span><br><span class="line">1D7USxwbub2kdSTd1Qr3pFbyPiqGmO2YjrvJCnXPH1ofq6gWWTH46Q0uxrNjp2Xn</span><br><span class="line">ZAPG03I+2gyGzs4ASSdFbDJwmQ6t0Pk253qArlzlcQgrGqtRS/4SzfivYiO6B27u</span><br><span class="line">aon8174Us7cCgYAYDsjOxV9wwtV/JXcfkRheZqGnWlOOCuW+Xp0+b+IdV0w0/TY+</span><br><span class="line">M+iYtmV0n/k3sK8p907ib8ftQ/stXYJ5BBUI61iPZHUSjZUC+dbn3oEDj7i7APfW</span><br><span class="line">FP7zwoeun8ao4J9oPb+BfmVlQ7CRKlND8Srgqq9Dgc2PWWWQr9GayuksjQKBgQCM</span><br><span class="line">Vr2vK+LUPGJxefl+nnkg2c954ZPm7T0IOe1MbVikuHXXtKOALmKBK3ojxSfX3vsG</span><br><span class="line">uD2PdvGKR5LaoxUSEO16KN4J+OwBWXPE3iFUIm+GjhR/Y7z4UBWV2anEAPrZ47gU</span><br><span class="line">G8hxNq9TKUALhy4lPJHGRgIWbr0OzNX0gbMnluaQcQKBgDyQeTvFpPuziNltPVm0</span><br><span class="line">BEbD6mSgHTky1i5w/k2UiR72tUHb3ekx98fPc0YHqczYbc7l8vP7mDO0+ZmtdFmq</span><br><span class="line">JjcixY3ZlvWeVjZ/QlI7wpgCy5hsgSRnxdy94IrLhrA5zlL0dDC0mAVzTPzJltIX</span><br><span class="line">QrbpjdKjcOCrdDny0WUw+OX4</span><br><span class="line">-----END PRIVATE KEY-----</span><br></pre></td></tr></table></figure>
<h2 id="php代码部分"><a href="#php代码部分" class="headerlink" title="php代码部分"></a>php代码部分</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 上文中的私钥</span></span><br><span class="line">$privateStr = <span class="string">'&lt;&lt;&lt;privateKey'</span></span><br><span class="line">xxxxxxxxxxxxxxxxxxxxxxxx</span><br><span class="line">xxxxxxxxxxxxxxxxxxxxxxxx</span><br><span class="line">xxxxxxxxxxxxxxxxxxxxxxxx</span><br><span class="line">xxxxxxxxxxxxxxxxxxxxxxxx</span><br><span class="line">privateKey;</span><br><span class="line"></span><br><span class="line">$pKey = openssl_pkey_get_private($privateStr);</span><br><span class="line"></span><br><span class="line"><span class="comment">//encoded 为 上文js加密后的密文</span></span><br><span class="line">$encoded = base64_decode($encoded);</span><br><span class="line"></span><br><span class="line"><span class="comment">//解密</span></span><br><span class="line">openssl_private_decrypt($encoded,$decrypted,$pKey,OPENSSL_PKCS1_PADDING);</span><br><span class="line"></span><br><span class="line"><span class="keyword">echo</span> $decrypted;</span><br><span class="line"><span class="comment">//如果一切正常的话，就能解密出结果 hello world</span></span><br></pre></td></tr></table></figure>
<h1 id="一些说明"><a href="#一些说明" class="headerlink" title="一些说明"></a>一些说明</h1><h2 id="官方说明"><a href="#官方说明" class="headerlink" title="官方说明"></a>官方说明</h2><p> php的openssl 扩展官网 <a href="http://php.net/manual/en/ref.openssl.php" target="_blank" rel="noopener">点击进入</a></p>
<h2 id="创建密钥对"><a href="#创建密钥对" class="headerlink" title="创建密钥对"></a>创建密钥对</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ssl = openssl_pkey_new([]);</span><br></pre></td></tr></table></figure>
<h2 id="提取私钥"><a href="#提取私钥" class="headerlink" title="提取私钥"></a>提取私钥</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">openssl_pkey_export($res, $privKey);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">echo</span> $privKey;</span><br><span class="line"></span><br><span class="line"><span class="comment">//privKey 就为私钥 格式为 </span></span><br><span class="line"><span class="comment">// -----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="comment">// xxxxxxxxxx</span></span><br><span class="line"><span class="comment">// xxxxxxxxxx</span></span><br><span class="line"><span class="comment">// xxxxxxxxxx</span></span><br><span class="line"><span class="comment">// xxxxxxxxxx</span></span><br><span class="line"><span class="comment">// -----END PRIVATE KEY-----</span></span><br></pre></td></tr></table></figure>
<h2 id="获取detail，包括公钥、模、指数等信息"><a href="#获取detail，包括公钥、模、指数等信息" class="headerlink" title="获取detail，包括公钥、模、指数等信息"></a>获取detail，包括公钥、模、指数等信息</h2><h3 id="方式一，从密钥对里面提取"><a href="#方式一，从密钥对里面提取" class="headerlink" title="方式一，从密钥对里面提取"></a>方式一，从密钥对里面提取</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//获取detail</span></span><br><span class="line">$detail = openssl_pkey_get_details($ssl);</span><br><span class="line"></span><br><span class="line"><span class="comment">//公钥</span></span><br><span class="line">$publicKey = $detail[<span class="string">'key'</span>];</span><br><span class="line"></span><br><span class="line"><span class="comment">//模，值为二进制乱码，转为16进制</span></span><br><span class="line">$module = $detail[<span class="string">'rsa'</span>][<span class="string">'n'</span>];</span><br><span class="line">$module = bin2hex($module);</span><br><span class="line"></span><br><span class="line"><span class="comment">//指数，值为二进制乱码，转为16进制</span></span><br><span class="line">$exponent = $detail[<span class="string">'rsa'</span>][<span class="string">'e'</span>];</span><br><span class="line">$exponent = bin2hex($exponent); <span class="comment">//一般结果为 010001 （65537）</span></span><br></pre></td></tr></table></figure>
<h3 id="方式二，从私钥里提取"><a href="#方式二，从私钥里提取" class="headerlink" title="方式二，从私钥里提取"></a>方式二，从私钥里提取</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//获取detail</span></span><br><span class="line">$privateKeySource = openssl_get_privatekey($privKey);</span><br><span class="line">$detail = openssl_pkey_get_details($privateKeySource);</span><br><span class="line"></span><br><span class="line"><span class="comment">//后面取模、指数等信息同 方式一</span></span><br></pre></td></tr></table></figure>
<h3 id="方式三，从公钥里提取"><a href="#方式三，从公钥里提取" class="headerlink" title="方式三，从公钥里提取"></a>方式三，从公钥里提取</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//$publicKey 为方式一中提取的 publicKey </span></span><br><span class="line">$publicKeySource = openssl_get_publickey($publicKey);</span><br><span class="line">$publicKeyDetail = openssl_pkey_get_details($publicKeySource);</span><br><span class="line"></span><br><span class="line"><span class="comment">//后面取模、指数等信息同方式一</span></span><br><span class="line"><span class="comment">//从公钥里面提取的 detail 的内容较少</span></span><br></pre></td></tr></table></figure>
<h2 id="解密"><a href="#解密" class="headerlink" title="解密"></a>解密</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// $encoded 为已被加密的密文</span></span><br><span class="line">$encoded = base64_decode($encoded);</span><br><span class="line"></span><br><span class="line"><span class="comment">//私钥</span></span><br><span class="line">$pKey = openssl_pkey_get_private($privKey);</span><br><span class="line"></span><br><span class="line"><span class="comment">//私钥解密</span></span><br><span class="line">openssl_private_decrypt($encoded,$decoded,$pKey,OPENSSL_PKCS1_PADDING);</span><br><span class="line"></span><br><span class="line"><span class="keyword">echo</span> $decoded;</span><br></pre></td></tr></table></figure>
<h1 id="完整的实例"><a href="#完整的实例" class="headerlink" title="完整的实例"></a>完整的实例</h1><h2 id="说明"><a href="#说明" class="headerlink" title="说明"></a>说明</h2><p>以下内容基于 phalcon 的 controller ，如果你没有使用phalcon，可能会修改一部分代码</p>
<p>controller里面有三个action</p>
<blockquote>
<p>index：html 页面，包括js加密部分</p>
</blockquote>
<blockquote>
<p>decode：php 解密部分，接收post数据，与页面index 的ajax交互</p>
</blockquote>
<blockquote>
<p>create：展示了创建密钥对</p>
</blockquote>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">    * <span class="doctag">@brief</span></span></span><br><span class="line"><span class="comment">    * Created by PhpStorm.</span></span><br><span class="line"><span class="comment">    * User: zy&amp;cs</span></span><br><span class="line"><span class="comment">    * Date: 17-3-2</span></span><br><span class="line"><span class="comment">    * Time: 上午11:47</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"><span class="keyword">namespace</span> <span class="title">App</span>\<span class="title">Modules</span>\<span class="title">Tester</span>\<span class="title">Controllers</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">RsaController</span> <span class="keyword">extends</span> <span class="title">ControllerBase</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * 内置了几个私钥，用该方法获取一个，</span></span><br><span class="line"><span class="comment">    *</span></span><br><span class="line"><span class="comment">    * 可以自己用 createAction 自己往后面加，实际操作中用缓存或数据库就能解决了</span></span><br><span class="line"><span class="comment">    *</span></span><br><span class="line"><span class="comment">    *</span></span><br><span class="line"><span class="comment">    * <span class="doctag">@param</span> bool|int $key 默认取第一个，$key === false 时，取所有</span></span><br><span class="line"><span class="comment">    * <span class="doctag">@return</span> array</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">    <span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">rsaPrivateKey</span><span class="params">($key=false)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $rsaKeys = [];</span><br><span class="line"></span><br><span class="line">        $rsaKeys[<span class="number">0</span>] = <span class="string">&lt;&lt;&lt;rsakey</span></span><br><span class="line"><span class="string">-----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="string">MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDMYA9a+x7XxFh8</span></span><br><span class="line"><span class="string">Ihk9EK+6N0xZNq8qhBH5jypFO7zVvOHYPDjr1OAoKXYESDF5Yk+bbivXRY3Ptjbb</span></span><br><span class="line"><span class="string">QF2f0kNTkGBO0bwUmmDJ8RWs14uA+OyPmByHpBxRDLvddNNe3sj0GWbOKMXhSNQD</span></span><br><span class="line"><span class="string">zdu+U7vCtpjrHfKcoa8X5VjVln/A/gmQ4sCl3eQgeWcBciMV1AMY3b5Ez3ZuVM2C</span></span><br><span class="line"><span class="string">HNQl4dyGzMtEmSxOTT9oFFlDI64q+6QjlDOeo0cOD3lZDuR7x1knXWtLJtQ4v2Al</span></span><br><span class="line"><span class="string">8Ovoci6b33DApSRJJCFMclIhakIRHfmQxSANxu7L25OslJ0UhbOZEVoWm5hkkjrC</span></span><br><span class="line">h3opznJjAgMBAAECggEBAIFHgm8ayrfSC+b56t0l4QL6V+FXJhbO1E/<span class="number">4</span>r9R7pUfO</span><br><span class="line"><span class="number">403</span>VSmxjjCfbkjvDLwiJl7HKTxEtfjcWHD00ygR/DPefLEyvfznJLdCQIBXlguli</span><br><span class="line">jMGIhwOGXCMo2u2LKOmqI5PFPbLLN+D6IKMHZSlP7kWNG84ec4mA/TEwcrEpMkbx</span><br><span class="line">SaK7J5psPJ14OwRyj3Ok/Q7cF6jfqWmBKDVErHlsQHrqVVuq3Ik67u9E4bQvdgRC</span><br><span class="line">A+<span class="number">1</span>z61ruu9pmyNhGBj0KsQCBU/e+<span class="number">4</span>X1TpKVPgnBS/q2qLGT5JwL556Fax5xiT4Pj</span><br><span class="line">uFI607WXdjsl5Zi1pYbxTJBgJhfeUs64pRkwHzMp/<span class="number">4</span>ECgYEA7b5PwkozKiYWFBzq</span><br><span class="line">JhutrykTTAZj+L4WomV3fwWNYJLboBX4fq7w4/rOP1xQtbtlSVeQxRV6+uka8QU5</span><br><span class="line">f+f+cH+/h2d/G0/ppwOPuavkW4pXhYNFlrJ6l9/KMG9Niw+R4Jrf09h47QgEXfjm</span><br><span class="line">uJfBlTnLb5FyvZ0miAcuabuhoh8CgYEA3BHHZPsDaJpSLaoN8RUYfbTyOU1kj4Pp</span><br><span class="line"><span class="number">4</span>N7psZ5AKxZblBMPYubZMcR+accZ2TDlch4rZJBOyfay6Cw4ZzneKeUO5NI/hr2g</span><br><span class="line">Qh6Zd2ZpxHEE8SxYRDOOf3l8gP83aspLzL8KT/XNySJraRacaknXETiP+pNcKqFo</span><br><span class="line">zy0J3ujVDz0CgYBKnsM1/kgU4KNpaLHtiB55rfDKme7i8fb0vdhF3B5Fw5J/qqW2</span><br><span class="line">TX56cAwwQu9qOwlNfdiIo3dYLbYxFCy6Ar0P3mjlPQzeK7TwoOOJqXQhb0iNNWiw</span><br><span class="line">JhDofmtdzHGQRjDJSJMcUQOTkkKcpDT2l1tBVUSPHh3feeXQKEDfGu9ejQKBgQCR</span><br><span class="line">XYUSZORZgiZqV3wiFUc6Mf4Wb9LPIdmpWlWPp/LHA1u2sehl8grh3uOJx6SBXNUS</span><br><span class="line">zm7nXJNOwRBoYF1ZglYH4nA2IdMok7V6N3Az+IhA5E7ZZ+teEZg9B+h/<span class="number">5</span>RWcCsiL</span><br><span class="line">FF4hd0JZa8z7e54Sb3gKvgwM/q3Q0xHCWAO/JJkoGQKBgQCXP+SGszS+YExHp+zO</span><br><span class="line">Bv1KRtv98YO9hZq9c+eXbVVbqEOo2/QM3G6joSdla7fD4SuEHA0MoEalgPkZ2teV</span><br><span class="line">+Wsq/CbbrlZTTbdjMXuJu6VY7aKXG4nq3ZaU1cjxKSovP5S4NNueCNvUYWXp218E</span><br><span class="line">S19cTtlOxaiqzUFB6csgohAxwQ==</span><br><span class="line">-----END <span class="keyword">PRIVATE</span> KEY-----</span><br><span class="line">rsakey;</span><br><span class="line"></span><br><span class="line">        $rsaKeys[<span class="number">1</span>] = <span class="string">&lt;&lt;&lt;rsakey</span></span><br><span class="line"><span class="string">-----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="string">MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDETB/jy7cTG9SN</span></span><br><span class="line"><span class="string">EAgqh+wgIn7BCjBUGYP5po5oAYSsksQeMzBow2upsAw1JTizUwPyRhiuA7+WCUNg</span></span><br><span class="line"><span class="string">W65zh4Lj/gnjRa2SQWAx1PgUh5xhKJBKU84UPrPRt6CRL5HRdqL6vi0YU26lpewS</span></span><br><span class="line"><span class="string">HPC2TWVuXyQrKGPLCkcRG0gnWEyCN53Ua/zpYYas3gNr3Qs64ZT60VIGXdXktpbS</span></span><br><span class="line"><span class="string">ozdofOmI8rXUzzVJbj5ahlnGzTtM+XBtlDvY2Sb2sB3FjH6jXLyTdr26AcpuSRJQ</span></span><br><span class="line"><span class="string">ZAJffHBm1bZwWJszpVKYNP7bYpt/Ey5uCuJUNq/XlNlmKKN5H9mzG2UITirduxRv</span></span><br><span class="line"><span class="string">vfV+QzVDAgMBAAECggEAdKO/Nz5vVF1vGTrzf0Iw3o9gvhfty6s1rnx3lfmA+oJj</span></span><br><span class="line"><span class="string">IobMNxQXv0aqmlG5tWSYrbdVJuF3UBHFBVa0/FUDQ7JJ8dAPaR6LqFCh8KD8HQdb</span></span><br><span class="line"><span class="string">Za8SfxkbBHyWXm7juJFEGrYyWYgJ8Uf8VG754Xlv0fuapEJludorjFCnuSlQnPag</span></span><br><span class="line">tw6t3tcj/BzbXTrrGi6V36vm9lkg4qrdozJcYl9cIXs/SAdWUX5jIkCAHVSrNoKA</span><br><span class="line">LSwylPeNMSVzJu3o6ivj4OPfn6/HuNZZ3Z18O/veNB13B4xb4M9f7RduQQFNC9Bq</span><br><span class="line">qH8nyfRiYtFFFj3SRfmF74GJCYe3xP4MDB3PV5DpUQKBgQDnpt1qqPiVbuaL4Kro</span><br><span class="line">a3b62u66RZnZxGCvvpaBeP7+cx69RGwcXxfYRNVSQ3VRbChuhsbw9UWrFY+akOT7</span><br><span class="line"><span class="number">5</span>QLCorxpyaSiYkv0aHpFqjWX9IaKY3PJN7hq7VICHTRehdpiNpp1Y092HWz6+qxn</span><br><span class="line"><span class="number">4</span>h8D4+bTmyQmU7S5gvfc5H00xwKBgQDY7fcXAfbuxnKw8j8BZQAhkjF2RvN0DGD/</span><br><span class="line">Uocee06LKrXzGWwP0ydCismxL50DvsddmJ92CEHqBtf8zoq32MlMTlCyBvSmFx/Z</span><br><span class="line">PEKalHxNlHuDDjnMSI4yYhd9losFhagXI767Uhce28AiNoHKd8dXM+<span class="number">8</span>NY77QxZJ9</span><br><span class="line">g/yzyatHpQKBgA1vbx4ViL1Z/kMUl7T9LpxkAD6LdN3dduIagq4lr1xgnuLJSh/n</span><br><span class="line">IAHqFBk+UlqTlFC8vmMRRqYijP6g8rbtVFiniZf1GvhUDSWyvYy2z37trrPuCrQb</span><br><span class="line"><span class="number">6</span>DVDaGM5AGWPC9hwZEr0pJIsKLrxuPgZdEUMfcG+GL2kUzIDN473LY/XAoGANcji</span><br><span class="line">f5DcIZ2QaDDX0EezfZ9apiG3UOmUzxkuKS+XbMfdLvX5pf7LeCMjGMxeWMRfd+RU</span><br><span class="line">fRZVCWpC+QpYuHaGimXMeidhVyDao6jeNqdkHnQXH4pSaEUBBJrvihLeSzM1Vu9k</span><br><span class="line"><span class="number">5</span>drXoq4HeDQdgA6snQFiXuaBNBAYXwhvikAROIUCgYEA3SkKhaZVXgsfIQpKwR1F</span><br><span class="line">WrTgh1976+<span class="number">40</span>ZY8a1Ktg9W7HJm8FmyEcsgnZxVM0IMVZ4W6LS1HboNL3XR0C7UtC</span><br><span class="line">Ga/EXZWqau7eMuob1lz9MyxQMYtiNKRBpGrJyo9HoFjS1M4xVGyVq0C6V3SplMB4</span><br><span class="line">vjjY7Snq6YKVk8Rw770Tnus=</span><br><span class="line">-----END <span class="keyword">PRIVATE</span> KEY-----</span><br><span class="line">rsakey;</span><br><span class="line"></span><br><span class="line">        $rsaKeys[<span class="number">2</span>] = <span class="string">&lt;&lt;&lt;rsakey</span></span><br><span class="line"><span class="string">-----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="string">MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDg8eZ6Ph5UsYIK</span></span><br><span class="line">SB8d/JhUVUK4Xq7BSWJ1kVk8GaJbO2zaqpNG2D72lRk/omjj7SfJtX3Ptbb7hz1k</span><br><span class="line">b6OUcQXkrPB+<span class="number">32</span>I9MhiB2JMODP05EZHy6zs+s98kCfJblrK9TF0ur0K0MFnS/duv</span><br><span class="line">W+Uef2bmm2F/<span class="number">4</span>xnfwq0lZ6hB12XrDfW6tjEUbrb9VogChligrq8cvUcL9De8+mZB</span><br><span class="line">FZ6ML4V7DH2AYybG0wN96tHsRjZz4Mow1R6vf3Drev1Gp2X7X7TIl5Gkz0xAcuTS</span><br><span class="line">nV3t6Q113C2Waa64iBM/NJF5Jk7/LfC879oR/awytX914tIHKtwRfdrDvqj0MSUy</span><br><span class="line">KFlL8EGbAgMBAAECggEBAIWKtpRd6m3HT/dAp9CKk/iFAW4pL8AqC9zWJE7MvRlC</span><br><span class="line">ZzZNy89kM8T58RpZFcIymctjBsTYEUC0IhtNN6S5kJEYplH71fuUkP4NEAhoZ7CI</span><br><span class="line">oMfBJNPtvwxLJ2l+RrCg9DTx8Ty986WR9ejeOmBnrDQ9jJ16unKfxWEOb9JeyO/I</span><br><span class="line">pcuNi1+FKjCJDExNrEbPsiVdHK3tWI7a3lKVA6pTVSypjp3gLlbxwHpgVaEm+dak</span><br><span class="line">RFiPoyCoxYigQhsmnKp0ou+<span class="number">2</span>qrJIl7b6NM+mfWD/o21zhAD3q/<span class="number">2</span>vDfc5M661Uhlj</span><br><span class="line">Q/CvinB6P39Zs4gIhZa17AeZOXEgekcx/I068vLRKLkCgYEA9xaztzsvJTOQOjYX</span><br><span class="line">ZAaTssVO1VpDp9YbaXzLhrmc9HZVTgIiuDumKHrZ98r0yxQ21CszyJUEVbDSmVze</span><br><span class="line">hYnkMpC6lV03H8KuODNtjbeUkEw87g3+wiEuDAPUPHpVo/Afzxnd3kvH0dOKkMkY</span><br><span class="line">H09tuBbI7JXEbeJtxOuCxc7QCT0CgYEA6Q7AXNnerxcIcfBmFQR2HArmcIQcfmyx</span><br><span class="line"><span class="number">1</span>D7USxwbub2kdSTd1Qr3pFbyPiqGmO2YjrvJCnXPH1ofq6gWWTH46Q0uxrNjp2Xn</span><br><span class="line">ZAPG03I+<span class="number">2</span>gyGzs4ASSdFbDJwmQ6t0Pk253qArlzlcQgrGqtRS/<span class="number">4</span>SzfivYiO6B27u</span><br><span class="line">aon8174Us7cCgYAYDsjOxV9wwtV/JXcfkRheZqGnWlOOCuW+Xp0+b+IdV0w0/TY+</span><br><span class="line">M+iYtmV0n/k3sK8p907ib8ftQ/stXYJ5BBUI61iPZHUSjZUC+dbn3oEDj7i7APfW</span><br><span class="line">FP7zwoeun8ao4J9oPb+BfmVlQ7CRKlND8Srgqq9Dgc2PWWWQr9GayuksjQKBgQCM</span><br><span class="line">Vr2vK+LUPGJxefl+nnkg2c954ZPm7T0IOe1MbVikuHXXtKOALmKBK3ojxSfX3vsG</span><br><span class="line">uD2PdvGKR5LaoxUSEO16KN4J+OwBWXPE3iFUIm+GjhR/Y7z4UBWV2anEAPrZ47gU</span><br><span class="line">G8hxNq9TKUALhy4lPJHGRgIWbr0OzNX0gbMnluaQcQKBgDyQeTvFpPuziNltPVm0</span><br><span class="line">BEbD6mSgHTky1i5w/k2UiR72tUHb3ekx98fPc0YHqczYbc7l8vP7mDO0+ZmtdFmq</span><br><span class="line">JjcixY3ZlvWeVjZ/QlI7wpgCy5hsgSRnxdy94IrLhrA5zlL0dDC0mAVzTPzJltIX</span><br><span class="line">QrbpjdKjcOCrdDny0WUw+OX4</span><br><span class="line">-----END <span class="keyword">PRIVATE</span> KEY-----</span><br><span class="line">rsakey;</span><br><span class="line"></span><br><span class="line">        $rsaKeys[<span class="number">3</span>] = <span class="string">&lt;&lt;&lt;rsakey</span></span><br><span class="line"><span class="string">-----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="string">MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0ZJCQOOdXAGtSN1W</span></span><br><span class="line">MBNQp27kzLC7qE275nNgJsxk7VN2okNDPoTyn2jKO66VSy6j2Jgnsa2Ivd8w0kZQ</span><br><span class="line">s96viwIDAQABAkANFdDFNHES2Zf0QL2s6sfSbH4kubQ94fyleva59XEn0D1RtQou</span><br><span class="line">ELkG8ziIYbqucTMJm5IkyR7wFYDCDuGgDU6BAiEA9hRhdeQfdwLzNUQfrReNEScL</span><br><span class="line">LhDMGbDqVsEvu8ik8zsCIQDaBRndLKubqbTtE/HP6tFG8bNHLpCfRbv+YTBgbyvP</span><br><span class="line"><span class="number">8</span>QIgfdbKSClSVd/yU2j08eU7RGw88V+xn+myzI6aRGNExwUCIHBIIEHgN6E7jYpr</span><br><span class="line">syW5cX5wDDykpqbgaylfNGL13kKBAiAZwTtHJmMuApSOrdesqoeNMOqKhoDgyNZy</span><br><span class="line">GbnWQa+Dxg==</span><br><span class="line">-----END <span class="keyword">PRIVATE</span> KEY-----</span><br><span class="line">rsakey;</span><br><span class="line"></span><br><span class="line">        $rsaKeys[<span class="number">4</span>] = <span class="string">&lt;&lt;&lt;rsakey</span></span><br><span class="line"><span class="string">-----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="string">MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMpVIE75OR2lftwn</span></span><br><span class="line">U2WXszG5YPCxZno7Q2cdfpXQ2aW69hcdjiQDgBeVfSngRtrK2lXlkiBw5wIuK9MI</span><br><span class="line">e0jL1tatPRJ+/kHSnQadh01NpHsz/FiMQsJ8jOdfP2zhCO6F6p6cgTH7ccSp3AHq</span><br><span class="line">XvmGIPZByba5N3KVgqSayux4cDQhAgMBAAECgYArPA1vUqn1v8tf17dmWggcc/RW</span><br><span class="line">+lFfhRJeElteQAaB93VmcxZQc78HSxY3wIjjb70/<span class="number">5</span>ZJYBEgYmy0aJxHQ+F2rmE7J</span><br><span class="line">viFtDUNp3wC64juvntuSoEOBjmjYVYhfNHOvoVrh/Lh8/<span class="number">8</span>cj5bba2D2/G0h+DAhC</span><br><span class="line">NuHDA2yesAmUm3icEQJBAPROBPTAHSdAh46osdpnjFp1skrsK5ZAzvLzvNGA9WtO</span><br><span class="line"><span class="number">581</span>u7cbKdmfKZOa/<span class="number">0</span>G3grOtC9reRovNxHzyLqhcD9HMCQQDUBLuNsdZOfOe5fRnl</span><br><span class="line">oH3Bs/U63VHpGuhD619kX3ZFC9J0yykSk37eWm6+lXJ9iEmMOpbIByzEzt5FvxCQ</span><br><span class="line">teQbAkBk0gXNk7L0Tfcjco7jWTRc6JGJxek++sPtE5VqyFN/<span class="number">03</span>JqH0tVbJxsvOPj</span><br><span class="line">LmmvzrbN6Da1Dw82dAq2C9VH5kPtAkAE18rU9L/<span class="number">5</span>cP72DLZ/uUfGGe87Ff0d/wBZ</span><br><span class="line">NNIr/<span class="number">8</span>Y604dOJandg8L9H0GyVsWTun47lscE8K0EHdmT7EZbl9wLAkEA5vV71Jk8</span><br><span class="line">zxGDhpDdqmviFDTMGjl2zQwIh8AW+OL+R1GAlsJlcWy0E4C6lm3xohv5vO1V9Png</span><br><span class="line">nWMKYJf8FW2DvA==</span><br><span class="line">-----END <span class="keyword">PRIVATE</span> KEY-----</span><br><span class="line">rsakey;</span><br><span class="line"></span><br><span class="line">        $rsaKeys[<span class="number">5</span>] = <span class="string">&lt;&lt;&lt;rsakey</span></span><br><span class="line"><span class="string">-----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="string">MIIBFAIBADANBgkqhkiG9w0BAQEFAASB/zCB/AIBAAIzAVKoys24WgfliPeAh2LH</span></span><br><span class="line"><span class="string">vhFEQ1KmxEETTrOwjSLtYFgA6opEvcND4Hie61syD3i/g7sBAgMBAAECMwDfbilP</span></span><br><span class="line"><span class="string">DH+pkhCJaizoSOvnLGhWUVxNqtVSKTXJX/Nri/a5Ye3sr+ZZIaCcxZCeBOejIQIa</span></span><br><span class="line"><span class="string">AbPKiMN2IzV+WpDMr9zspM1Khz2Hy3y0hKUCGgDG8O8syaInZ7/qdrn2/1TIuZkO</span></span><br><span class="line"><span class="string">CkE4+KItAhlgyLtlBai+Kai9fegU3a2gNkwg2zbTJFhNAhkyNURnrUu7XjfVWLl+</span></span><br><span class="line"><span class="string">WNpw/kZegMANPNLRAhoBgZPB6KHFUtqcodgnJvRkyt8wVlUk0Lx6Qg==</span></span><br><span class="line"><span class="string">-----END PRIVATE KEY-----</span></span><br><span class="line"><span class="string">rsakey;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span>($key === <span class="keyword">false</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> $rsaKeys;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (!<span class="keyword">isset</span>($rsaKeys[$key])) &#123;</span><br><span class="line">            $key=<span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $rsaKeys[$key];</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">        * <span class="doctag">@param</span> $id</span></span><br><span class="line"><span class="comment">        * <span class="doctag">@return</span> array</span></span><br><span class="line"><span class="comment">        */</span></span><br><span class="line">    <span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">getDetailFromPKId</span><span class="params">($id)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $key = <span class="keyword">$this</span>-&gt;rsaPrivateKey($id);</span><br><span class="line">        $resource = openssl_get_privatekey($key);</span><br><span class="line">        <span class="keyword">return</span>  openssl_pkey_get_details($resource);;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">getHtml</span><span class="params">($keyId,$rsaModule,$rsaExponent)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//rsa 的那几个js</span></span><br><span class="line">        $rsaAssets = [</span><br><span class="line">            <span class="string">'jsbn.js'</span>,</span><br><span class="line">            <span class="string">'prng4.js'</span>,</span><br><span class="line">            <span class="string">'rng.js'</span>,</span><br><span class="line">            <span class="string">'rsa.js'</span>,</span><br><span class="line">            <span class="string">'base64.js'</span>,</span><br><span class="line">        ];</span><br><span class="line">        $rsaJsPre = <span class="string">'http://blog.lopy.win/assets/rsa/'</span>;</span><br><span class="line">        $rsaJs = <span class="string">''</span>;</span><br><span class="line">        <span class="keyword">foreach</span>($rsaAssets <span class="keyword">as</span> $val)&#123;</span><br><span class="line">            $rsaJs .= <span class="string">'&lt;script src="'</span> . $rsaJsPre . $val . <span class="string">'"&gt;&lt;/script&gt;'</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="comment">//切换 privateKey</span></span><br><span class="line">        $switchStr = <span class="string">''</span>;</span><br><span class="line">        <span class="keyword">foreach</span>(<span class="keyword">$this</span>-&gt;rsaPrivateKey() <span class="keyword">as</span> $key=&gt;$val)</span><br><span class="line">        &#123;</span><br><span class="line">            $switchStr .= <span class="string">'&lt;li&gt;&lt;a href="index?key_id='</span> . $key . <span class="string">'"&gt;密钥 - '</span> . $key . <span class="string">' &lt;/a&gt;&lt;/li&gt;'</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="comment">//密钥长度</span></span><br><span class="line">        $moduleLength = strlen($rsaModule) * <span class="number">8</span> / <span class="number">2</span>; <span class="comment">//为毛要除以2 ，因为 bin2hex 后，长度为两倍</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//html 代码</span></span><br><span class="line">        $html = <span class="string">&lt;&lt;&lt;html</span></span><br><span class="line"><span class="string">&lt;html&gt;</span></span><br><span class="line"><span class="string">&lt;head&gt;</span></span><br><span class="line"><span class="string">&lt;script src="//cdn.bootcss.com/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"><span class="subst">$rsaJs</span></span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&lt;/head&gt;</span></span><br><span class="line"><span class="string">&lt;body&gt;</span></span><br><span class="line"><span class="string">&lt;script&gt;</span></span><br><span class="line"><span class="string">    //class rsa</span></span><br><span class="line"><span class="string">    var MyRsa = function(key,eVal)&#123;</span></span><br><span class="line"><span class="string">        key = key || '';</span></span><br><span class="line"><span class="string">        eVal = eVal || '010001';</span></span><br><span class="line"><span class="string">        var rsaObj = new RSAKey();</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        var init = function(key,eVal)&#123;</span></span><br><span class="line"><span class="string">            if(key)&#123;</span></span><br><span class="line"><span class="string">                rsaObj.setPublic(key,eVal);</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">        &#125;;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        this.encrypt = function(str)&#123;</span></span><br><span class="line"><span class="string">            var strEncoded = rsaObj.encrypt(str);</span></span><br><span class="line"><span class="string">            if(!strEncoded)&#123;</span></span><br><span class="line"><span class="string">                alert('hello what\'s your name');</span></span><br><span class="line"><span class="string">                return false;</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">            return hex2b64(strEncoded);</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">        init(key,eVal);</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">    function submitCheck()&#123;</span></span><br><span class="line"><span class="string">        var rsaModule = "<span class="subst">$rsaModule</span>";</span></span><br><span class="line"><span class="string">        var rsaExponent = "<span class="subst">$rsaExponent</span>";</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        var myRsa = new MyRsa(rsaModule,rsaExponent);</span></span><br><span class="line"><span class="string">        $("[name=input]").val(myRsa.encrypt($("#input").val()));</span></span><br><span class="line"><span class="string">        var url = "decode";</span></span><br><span class="line"><span class="string">        var data =&#123;</span></span><br><span class="line"><span class="string">            key_id:$("[name=key_id]").val(),</span></span><br><span class="line"><span class="string">            input:$("[name=input]").val(),</span></span><br><span class="line"><span class="string">        &#125;;</span></span><br><span class="line"><span class="string">        $.post(url,data,function(json)&#123;</span></span><br><span class="line"><span class="string">            if(json.flag ===0)&#123;</span></span><br><span class="line"><span class="string">                $('#decoded').val(json.decoded);</span></span><br><span class="line"><span class="string">            &#125;else&#123;</span></span><br><span class="line"><span class="string">                alert(json.msg);</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">        &#125;);</span></span><br><span class="line"><span class="string">        return false;</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">&lt;/script&gt;</span></span><br><span class="line"><span class="string">&lt;style&gt;</span></span><br><span class="line"><span class="string">    input.full&#123;</span></span><br><span class="line"><span class="string">        width: 100%;</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">&lt;/style&gt;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&lt;ul&gt;<span class="subst">$switchStr</span>&lt;/ul&gt;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&lt;form action="#" method="post"&gt;</span></span><br><span class="line"><span class="string">    &lt;ul&gt;</span></span><br><span class="line"><span class="string">        &lt;input type="hidden" name="key_id" value="<span class="subst">$keyId</span>"&gt;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        &lt;li&gt;&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;密钥长度&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;</span></span><br><span class="line"><span class="string">            &lt;input type="text" readonly value="<span class="subst">$moduleLength</span>" class="full"&gt;</span></span><br><span class="line"><span class="string">        &lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;模（n）&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;</span></span><br><span class="line"><span class="string">            &lt;input type="text" readonly value="<span class="subst">$rsaModule</span>" class="full"&gt;</span></span><br><span class="line"><span class="string">        &lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;指数（e）&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;</span></span><br><span class="line"><span class="string">            &lt;input type="text" readonly value="<span class="subst">$rsaExponent</span>" class="full"&gt;</span></span><br><span class="line"><span class="string">        &lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;输入要加密的字符串：&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;</span></span><br><span class="line"><span class="string">            &lt;input type="text" id="input" class="full"&gt;</span></span><br><span class="line"><span class="string">        &lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;js加密后&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;</span></span><br><span class="line"><span class="string">            &lt;input type="text" name="input" readonly class="full"&gt;</span></span><br><span class="line"><span class="string">        &lt;/li&gt;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        &lt;li&gt;&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;php解密后&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;&lt;input type="text" id="decoded" readonly class="full"&gt;&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;&lt;/li&gt;</span></span><br><span class="line"><span class="string">        &lt;li&gt;</span></span><br><span class="line"><span class="string">            &lt;button type="submit" onclick="return submitCheck();"&gt;encode &amp;&amp; decode&lt;/button&gt;</span></span><br><span class="line"><span class="string">        &lt;/li&gt;</span></span><br><span class="line"><span class="string">    &lt;/ul&gt;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">&lt;/form&gt;</span></span><br><span class="line"><span class="string">&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br><span class="line"><span class="string">html;</span></span><br><span class="line">        <span class="keyword">return</span> $html;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> bool</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">indexAction</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $keyId = <span class="keyword">$this</span>-&gt;request-&gt;get(<span class="string">'key_id'</span>,<span class="string">'int'</span>,<span class="number">0</span>);</span><br><span class="line">        $keyId = $keyId &lt; <span class="number">0</span> ? <span class="number">0</span> : $keyId;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//取一个私钥 private key</span></span><br><span class="line">        $detail = <span class="keyword">$this</span>-&gt;getDetailFromPKId($keyId);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//取得该密钥对的 模 和指数，也是 n 和 e</span></span><br><span class="line">        $rsaModule = strtoupper(bin2hex($detail[<span class="string">'rsa'</span>][<span class="string">'n'</span>]));</span><br><span class="line"></span><br><span class="line">        $rsaExponent = bin2hex($detail[<span class="string">'rsa'</span>][<span class="string">'e'</span>]);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//输出html</span></span><br><span class="line">        <span class="keyword">echo</span> <span class="keyword">$this</span>-&gt;getHtml($keyId, $rsaModule, $rsaExponent);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> bool</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">decodeAction</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">//post 参数</span></span><br><span class="line">        $keyId = <span class="keyword">$this</span>-&gt;request-&gt;getPost(<span class="string">'key_id'</span>, <span class="string">'int'</span>, <span class="number">0</span>);</span><br><span class="line">        $input = <span class="keyword">$this</span>-&gt;request-&gt;getPost(<span class="string">'input'</span>, [<span class="string">'string'</span>, <span class="string">'trim'</span>], <span class="string">''</span>);</span><br><span class="line">        $json = [</span><br><span class="line">            <span class="string">'flag'</span> =&gt; <span class="number">1</span>,</span><br><span class="line">            <span class="string">'msg'</span>  =&gt; <span class="string">''</span></span><br><span class="line">        ];</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span>($keyId &lt; <span class="number">0</span>)&#123;</span><br><span class="line">            $json[<span class="string">'msg'</span>] = <span class="string">'what\'s your name?'</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span> <span class="keyword">if</span>(!$input)&#123;</span><br><span class="line">            $json[<span class="string">'msg'</span>] = <span class="string">'how old are you'</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            $str = base64_decode($input);</span><br><span class="line"></span><br><span class="line">            <span class="comment">//私钥</span></span><br><span class="line">            $pKey = openssl_pkey_get_private(<span class="keyword">$this</span>-&gt;rsaPrivateKey($keyId));</span><br><span class="line"></span><br><span class="line">            <span class="comment">//私钥解密</span></span><br><span class="line">            openssl_private_decrypt($str,$decrypted,$pKey,OPENSSL_PKCS1_PADDING);</span><br><span class="line"></span><br><span class="line">            <span class="comment">//结果</span></span><br><span class="line">            $json[<span class="string">'flag'</span>] = <span class="number">0</span>;</span><br><span class="line">            $json[<span class="string">'decoded'</span>] = $decrypted;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">$this</span>-&gt;response-&gt;setJsonContent($json);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">//test</span></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">createAction</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;pre&gt;'</span>;</span><br><span class="line">        <span class="comment">//创建密钥对</span></span><br><span class="line">        <span class="comment">//$rsaPair = openssl_pkey_new([]);</span></span><br><span class="line"></span><br><span class="line">        $rsaPair = openssl_pkey_new([</span><br><span class="line">            <span class="string">'private_key_bits'</span>=&gt;<span class="number">401</span></span><br><span class="line">        ]);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//get 私钥</span></span><br><span class="line">        openssl_pkey_export($rsaPair, $privateKey);</span><br><span class="line"></span><br><span class="line">        var_dump($privateKey);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// get detail of private key</span></span><br><span class="line">        <span class="comment">//array(</span></span><br><span class="line">        <span class="comment">//  bits    位数</span></span><br><span class="line">        <span class="comment">//  key 公钥</span></span><br><span class="line">        <span class="comment">//  rsa =&gt; array(</span></span><br><span class="line">        <span class="comment">//      n 模</span></span><br><span class="line">        <span class="comment">// 。。。。。。</span></span><br><span class="line">        <span class="comment">//  )</span></span><br><span class="line">        <span class="comment">//  type</span></span><br><span class="line">        <span class="comment">//)</span></span><br><span class="line">        $privateKeyDetail = openssl_pkey_get_details($rsaPair);</span><br><span class="line"></span><br><span class="line">        <span class="comment">/*</span></span><br><span class="line"><span class="comment">        //这样也行，两种方法</span></span><br><span class="line"><span class="comment">        $privateKeySource = openssl_get_privatekey($privateKey);</span></span><br><span class="line"><span class="comment">        $privateKeyDetail = openssl_pkey_get_details($privateKeySource);</span></span><br><span class="line"><span class="comment">        */</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//get 公钥 public key</span></span><br><span class="line">        var_dump($privateKeyDetail[<span class="string">'key'</span>]);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        var_dump(<span class="string">'------------------------------------------ private key start ------------------------------------------'</span>);</span><br><span class="line">        <span class="comment">//模 n ，一般用hex 显示</span></span><br><span class="line">        var_dump(strtoupper(bin2hex($privateKeyDetail[<span class="string">'rsa'</span>][<span class="string">'n'</span>])));</span><br><span class="line">        <span class="comment">//指数 e</span></span><br><span class="line"></span><br><span class="line">        var_dump(bin2hex($privateKeyDetail[<span class="string">'rsa'</span>][<span class="string">'e'</span>]));</span><br><span class="line"></span><br><span class="line">        var_dump(strtoupper(bin2hex($privateKeyDetail[<span class="string">'rsa'</span>][<span class="string">'d'</span>])));</span><br><span class="line"></span><br><span class="line">        var_dump(<span class="string">'------ p and q ------'</span>);</span><br><span class="line">        var_dump((bin2hex($privateKeyDetail[<span class="string">'rsa'</span>][<span class="string">'p'</span>])));</span><br><span class="line">        var_dump((bin2hex($privateKeyDetail[<span class="string">'rsa'</span>][<span class="string">'q'</span>])));</span><br><span class="line"></span><br><span class="line">        var_dump(<span class="string">'------------------------------------------ private key end ------------------------------------------'</span>);</span><br><span class="line">        var_dump(<span class="string">''</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        var_dump(<span class="string">'------------------------------------------ public key start ------------------------------------------'</span>);</span><br><span class="line">        <span class="comment">//也可以用public key 获取 detail</span></span><br><span class="line">        <span class="comment">//public 的 detail 里面的 rsa 的东西要少些</span></span><br><span class="line">        $publicKeySource = openssl_get_publickey($privateKeyDetail[<span class="string">'key'</span>]);</span><br><span class="line">        $publicKeyDetail = openssl_pkey_get_details($publicKeySource);</span><br><span class="line"></span><br><span class="line">        var_dump(strtoupper(bin2hex($publicKeyDetail[<span class="string">'rsa'</span>][<span class="string">'n'</span>])));</span><br><span class="line">        var_dump(bin2hex($privateKeyDetail[<span class="string">'rsa'</span>][<span class="string">'e'</span>]));</span><br><span class="line"></span><br><span class="line">        var_dump(<span class="string">'------------------------------------------ public key end ------------------------------------------'</span>);</span><br><span class="line">        var_dump($publicKeyDetail);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/pre&gt;'</span>;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="引用"><a href="#引用" class="headerlink" title="引用"></a>引用</h1><ul>
<li><p>rsa<br>  <a href>http://www-cs-students.stanford.edu/~tjw/jsbn/</a></p>
</li>
<li><p>demo<br>  <a href>http://www-cs-students.stanford.edu/~tjw/jsbn/rsa.html</a></p>
</li>
</ul>

      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    Tony Java Z
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://blog.lopygo.com/2017/2017-2017-03-02-js-php-rsa/" title="rsatitle">https://blog.lopygo.com/2017/2017-2017-03-02-js-php-rsa/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/php/" rel="tag"># php</a>
          
            <a href="/tags/js/" rel="tag"># js</a>
          
            <a href="/tags/rsa/" rel="tag"># rsa</a>
          
        </div>
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div id="needsharebutton-postbottom">
            <span class="btn">
              <i class="fa fa-share-alt" aria-hidden="true"></i>
            </span>
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/2017-2017-02-20-debian-realtek-driver/" rel="next" title="debian realtek 无线网卡安装">
                <i class="fa fa-chevron-left"></i> debian realtek 无线网卡安装
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/2017-2017-03-17-debian-run-graphics-program-at-root/" rel="prev" title="debian 以root权限运行图形程序">
                debian 以root权限运行图形程序 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="Tony Java Z">
            
              <p class="site-author-name" itemprop="name">Tony Java Z</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

			<!--my custom code begin-->
			<script src="https://cdn.jsdelivr.net/npm/jquery@3.1.0/dist/jquery.min.js"></script>
			<script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.0/velocity.min.js"></script>
			<script type="text/javascript">
			  $("#sidebar").hover(function(){
				$("#mydivshow").velocity('stop').velocity({opacity: 1});
			  },function(){
				$("#mydivshow").velocity('stop').velocity({opacity: 0});
			  });
			</script>
			<div id="mydivshow" class="mydivshow">
			<!--my custom code end-->
			
          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">118</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">17</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">104</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/uljjmhn520" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:284141050 @qq.com" target="_blank" title="Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>Mail</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=pZedkZSRlJWQleXU1IvGysg" target="_blank" title="QQ邮我">
                    
                      <i class="fa fa-fw fa-envelope"></i>QQ邮我</a>
                </span>
              
            
          </div>

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lopygo.com" title="主站" target="_blank">主站</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://blog.csdn.net/u011475210" title="WordZzzCsdn" target="_blank">WordZzzCsdn</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://wordzzzz.github.io" title="WordZzzGitPage" target="_blank">WordZzzGitPage</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.choudalao.com" title="臭大佬" target="_blank">臭大佬</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://blog.wingflare.com" title="翼闪的奶嘴" target="_blank">翼闪的奶嘴</a>
                  </li>
                
              </ul>
            </div>
          

          
        </div>
		<!--my custom code begin-->
		</div>
		<!--my custom code end-->
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#开始说明"><span class="nav-number">1.</span> <span class="nav-text">开始说明</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#javascript加密"><span class="nav-number">2.</span> <span class="nav-text">javascript加密</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#引入相关的js库"><span class="nav-number">2.1.</span> <span class="nav-text">引入相关的js库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#js代码第一部分"><span class="nav-number">2.2.</span> <span class="nav-text">js代码第一部分</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#js代码第二部分"><span class="nav-number">2.3.</span> <span class="nav-text">js代码第二部分</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#php解密"><span class="nav-number">3.</span> <span class="nav-text">php解密</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#私钥"><span class="nav-number">3.1.</span> <span class="nav-text">私钥</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#php代码部分"><span class="nav-number">3.2.</span> <span class="nav-text">php代码部分</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#一些说明"><span class="nav-number">4.</span> <span class="nav-text">一些说明</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#官方说明"><span class="nav-number">4.1.</span> <span class="nav-text">官方说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建密钥对"><span class="nav-number">4.2.</span> <span class="nav-text">创建密钥对</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#提取私钥"><span class="nav-number">4.3.</span> <span class="nav-text">提取私钥</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#获取detail，包括公钥、模、指数等信息"><span class="nav-number">4.4.</span> <span class="nav-text">获取detail，包括公钥、模、指数等信息</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#方式一，从密钥对里面提取"><span class="nav-number">4.4.1.</span> <span class="nav-text">方式一，从密钥对里面提取</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#方式二，从私钥里提取"><span class="nav-number">4.4.2.</span> <span class="nav-text">方式二，从私钥里提取</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#方式三，从公钥里提取"><span class="nav-number">4.4.3.</span> <span class="nav-text">方式三，从公钥里提取</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解密"><span class="nav-number">4.5.</span> <span class="nav-text">解密</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#完整的实例"><span class="nav-number">5.</span> <span class="nav-text">完整的实例</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#说明"><span class="nav-number">5.1.</span> <span class="nav-text">说明</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#引用"><span class="nav-number">6.</span> <span class="nav-text">引用</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2025</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tony Java Z</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">72.9k</span>
  
</div>






  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a></div>




        
<div class="busuanzi-count">
  
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script src="https://cdn.jsdelivr.net/npm/jquery@2.1.3/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fastclick@1.0.6/lib/fastclick.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-lazyload@1.9.7/jquery.lazyload.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.2.2/velocity.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@1.2.2/velocity.ui.min.js"></script>




  
  <script src="https://cdn.jsdelivr.net/npm/jquery-fancybox@2.0.0/source/js/jquery.fancybox.pack.js"></script>



  
  <script src="https://cdn.jsdelivr.net/npm/canvas-nest.js@1.0.0/canvas-nest.min.js"></script>












  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>




  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("", "");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
      pbOptions = {};
      
          pbOptions.iconStyle = "box";
      
          pbOptions.boxForm = "horizontal";
      
          pbOptions.position = "bottomCenter";
      
          pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-postbottom', pbOptions);
    
    
  </script>

  

  
  


  
  <script type="text/javascript" src="/js/src/js.cookie.js?v=5.1.3"></script>
  <script type="text/javascript" src="/js/src/scroll-cookie.js?v=5.1.3"></script>


  
  <script type="text/javascript" src="/js/src/exturl.js?v=5.1.3"></script>



  
  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>


<script>
  console.log('%c本Blog仅用于个人学习',"color:orange; background:blue; font-size: 16pt");

  console.log('%c内容中有部分资源引用自互联网',"color:orange; background:blue; font-size: 16pt");

  console.log('%c如果不小心侵犯了您的权益，请联系  284141050@qq.com 处理相关信息',"color:orange; background:blue; font-size: 16pt");

</script>

</body>
</html>
